/*
 * TCSS 422 Process Control Simulator
 * Group Money: Al McKenzie, Michael Pitts, Taylor Zielske
 */

/**
 * A Process that uses (consumes) the shared data.
 * @author Michael Pitts
 * @version Dec 8, 2011
 */
public class Consumer extends AbstractSharedProcess {

	/**
	 * Creates a new Consumer, which uses the Shared data.
	 * @param the_name is the name of the new Consumer.
	 * @param the_limit is the number of iterations the Consumer should run.  If
	 * negative or zero will run forever.
	 * @param the_shared is the shared data to work on.
	 */
	public Consumer(final String the_name, final int the_limit, 
			final Shared the_shared) {
		super(the_name, the_limit, the_shared);
	}

	@Override SysCall work() {
		Main.out().println(toString() + " reading from Shared memory.");
		return SysCall.MEM_READ;
	}

	@Override boolean checkData() {
		return my_shared.memory_read() != 0;
	}

	@Override void done() {
		Main.out().println("Done consuming Shared data.");
		my_shared.memory_write(0);
	}
}
